package com.gisuni.sddc.platformManager.service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import com.gisuni.sddc.platformManager.dao.MessageInfoDao;
import com.gisuni.sddc.platformManager.model.MessageInfo;
import com.gisuni.sddc.platformManager.model.Response;


@IocBean
public class MessageInfoService {
	
	private Log log=Logs.getLog(MessageInfoService.class);
	
	@Inject
	private MessageInfoDao messageInfoDao;
	
	
	public List<MessageInfo> getShowAllMessage() {
		List<MessageInfo> messList=messageInfoDao.getShowMessageInfo();
		return messList;
	}


	public Response addNewMessage(HttpServletRequest request) {
		Response res=new Response();
		res.setSuccess(false);
		MessageInfo messageInfo=new MessageInfo();
		String id=request.getParameter("id");
	    String title=request.getParameter("title");
	    String content=request.getParameter("content");
	    String userId=request.getParameter("userId");
	    String userName=request.getParameter("userName");
	    Date pbtime=new Date();
	    Date uptime=new Date();
	    messageInfo.setId(id);
		messageInfo.setTitle(title);
		messageInfo.setContent(content);
		messageInfo.setPbtime(pbtime);
		messageInfo.setUptime(uptime);
		messageInfo.setStatus("1");
		messageInfo.setPbUserId(userId);
		messageInfo.setPbUserName(userName);
		boolean flag=messageInfoDao.addMessageInfo(messageInfo);
		if(flag){
			res.setSuccess(true);
			res.setMsg(id);
		}
		return res;
	}


	public MessageInfo getMessageById(String id) {
		MessageInfo messageInfo=messageInfoDao.getMessageById(id);
		return messageInfo;
	}

	public boolean updateMessage(String id, String title, String content) {
		return messageInfoDao.updateMessageById(id,title,content);
	}


	public List<MessageInfo> getAllMessage() {
		List<MessageInfo> messList=messageInfoDao.getAllMessageInfo2();
		return messList;
	}


	public boolean deleteMessage(String id) {
		return messageInfoDao.deleteMessage(id);
	}


	public boolean updateMessageStatus(String id, String flag) {
		return messageInfoDao.updateMessageStatus(id,flag);
	}


}
